package com.example.demo2;

import android.graphics.Bitmap;
import android.util.Log;
import android.util.LruCache;

import com.android.volley.toolbox.ImageLoader;

class BitmapCache implements ImageLoader.ImageCache {
    private final String TAG = "BitmapCache";
    private LruCache <String,Bitmap> lruCache;

    public BitmapCache() {
       int maxSize = 10*1024*1024;
       lruCache = new LruCache<String, Bitmap>(maxSize){
           @Override
           protected int sizeOf(String key, Bitmap value) {
               return value.getRowBytes()*value.getHeight();
           }
       };


    }

    @Override
    public Bitmap getBitmap(String s) {
        Bitmap bitmap = lruCache.get(s);
        if (bitmap==null){
            Log.e(TAG,"缓存器为空，还没有缓存图片");
        }
        else {
            Log.e(TAG,"缓存器不为空");
        }
        return bitmap;
    }

    @Override
    public void putBitmap(String s, Bitmap bitmap) {
        if (bitmap==null){
            Log.e(TAG,"缓存器放入图片失败");

        }
        else {
            Log.e(TAG,"缓存器放入图片成功");
        }

    lruCache.put(s,bitmap);
    }
}
